<template>
    <div class="tabs-content">
        <el-form
        :inline="true"
        :model="queryopsdata"
        style="display: flex; justify-content: space-between; align: center; margin: 0px 20px">
        <div style="display: inline-block">
          <el-form-item>
            <el-input v-model="queryopsdata.name" placeholder="请输入查询姓名"></el-input>
          </el-form-item>
          <el-form-item>
            <el-input v-model="queryopsdata.workId" placeholder="请输入查询工号"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="queryOps()">搜索</el-button>
          </el-form-item>
          <el-form-item>
            <el-button @click="getopsdataList()">重置</el-button>
          </el-form-item>
        </div>
      </el-form>
      <!-- 内容区域 start-->
      <el-table
          ref="opsdataList"
          :data="opsdataList"
          border
          height="91%"
          style="width:97.5%"
          :header-cell-style="{height: '7vh'}"
          :cell-style="cellStyle"
          @selection-change="handleSelectionChange"
          >
          <el-table-column
              type="index"
              :index="getIndex"
              header-align="center"
              align="center"
              label="ID">
          </el-table-column>
          <el-table-column
              prop="workId"
              header-align="center"
              align="center"
              label="用户工号">
          </el-table-column>
          <el-table-column
              prop="username"
              header-align="center"
              align="center"
              label="用户名">
          </el-table-column>
          <el-table-column
              prop="operation"
              header-align="center"
              align="center"
              :show-overflow-tooltip="true"
              label="用户操作">
          </el-table-column>
          <el-table-column
              prop="method"
              header-align="center"
              align="center"
              :show-overflow-tooltip="true"
              label="请求方法">
          </el-table-column>
          <el-table-column
              prop="params"
              header-align="center"
              align="center"
              :show-overflow-tooltip="true"
              label="请求参数">
          </el-table-column>
          <el-table-column
              prop="ip"
              header-align="center"
              align="center"
              :show-overflow-tooltip="true"
              label="IP地址">
          </el-table-column>
          <el-table-column
              prop="createTime"
              header-align="center"
              align="center"
              :show-overflow-tooltip="true"
              label="创建时间">
          </el-table-column>
          <el-table-column
              align="center"
              label="操作">
              <template slot-scope="scope">
                <!-- <el-link type="danger" @click="deleteHandle(scope.row)" icon="el-icon-delete"></el-link> -->
                <el-button type="danger" @click="deleteHandle(scope.row)" style="width:30%;height:3.5vh">删除</el-button>
              </template>
          </el-table-column>
        </el-table>
      <!-- 内容区域 end -->
      <!-- 分页器 -->
      <div class="block">
        <el-pagination
          align="right"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="[10, 15, 20]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
        </el-pagination>
      </div>
    </div>
</template>

<script>
export default {
  name: 'OpsLog',
  data() {
    return {
      queryopsdata: { // 查询框数据
        name: '',
        workId: ''
      },
      opsdataList: [], // 获取的登录日记数据
      multipleSelection: [], // 选定的多个复选框对象
      currentPage: 1,
      pageSize: 10,
      total: 0
    }
  },
  mounted() {
    this.getopsdataList()
  },
  methods: {
    // 表格行高
    cellStyle() {
      return {
        height: '5vh',
        padding: '0'
      }
    },
    // 改变当前页行数
    handleSizeChange(val) {
      this.pageSize = val
      this.currentPage = 1
      this.getopsdataList()
    },
    // 改变当前页码
    handleCurrentChange(val) {
      this.currentPage = val
      this.getopsdataList()
    },
    // 选择的复选框的数量
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    // 获取登录日志选定页码的数据
    getopsdataList() {
      this.getRequest('/log/ops/' + this.currentPage + '/' + this.pageSize).then((resp) => {
        if (resp) {
          this.total = resp.total
          this.opsdataList = resp.list
        }
      })
    },
    // 删除
    deleteHandle(data) {
      this.$confirm('此操作将永久删除第' + data.id + '操作信息，是否继续？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消'
      }).then(() => {
        this.deleteRequest('/log/ops/' + data.id).then((resp) => {
          if (resp) {
            this.$message.success('删除成功')
            this.getopsdataList()
          } else {
            this.$message.error('删除失败')
          }
        })
      }).catch(() => {
        this.$message.info('已取消删除')
      })
    },
    // 序号
    getIndex(index) {
      return index + (this.currentPage - 1) * this.pageSize + 1
    },
    // 高级查询
    queryOps() {
      this.getRequest(`/log/ops/query?page=${this.currentPage}&size=${this.pageSize}&name=${this.queryopsdata.name}&workId=${this.queryopsdata.workId}`).then(resp => {
        if (resp) {
          this.opsdataList = resp.data
          this.total = resp.data.length
        } else {
          console.log('错误')
        }
      })
    }
  }
}
</script>

<style scoped>
@import '../../assets/css/top-form.css';
@import '../../assets/css/table.css';
.tabs-content {
  width: 100%;
  height: 78vh;
}
/* .tabs-content .body-table {
  width: 97%;
  height: 81%;
  margin: 0 auto;
  overflow: hidden;
  overflow-y: auto;
} */
/** 分页器 start  */
.tabs-content > .block {
  position: absolute;
  top: 91%;
  right: 1.5%;
}
.tabs-content .el-pagination {
  align-items: center;
}
.tabs-content /deep/ .el-pagination span:not([class*=suffix]) {
  font: 1vw '宋体';
  padding-top: 0px;
}
.tabs-content  /deep/ .el-pagination .el-pagination__total {
  padding-top: 5px !important;
}
.tabs-content /deep/ .el-pagination .el-input__inner {
  font: 1vw '宋体';
}
/** 分页器 end */
</style>

